package org.afun.oldhand.forum.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.afun.oldhand.R;
import org.afun.oldhand.forum.javaBean.ItemTopBean;
import org.afun.oldhand.order.adapter.OrderItemAdapter;

import java.util.List;

public class ForumTopItemAdapter  extends RecyclerView.Adapter<ForumTopItemAdapter.ForumTopItemViewHolder> {

    private List<ItemTopBean> data;
    private Context context;
    private ForumTopItemAdapter.OnForumTopItemRecyclerItemClickListener onForumTopItemRecyclerItemClickListener;

    public ForumTopItemAdapter(List<ItemTopBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @NonNull
    @Override
    public ForumTopItemAdapter.ForumTopItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.forum_listitem1, null);
        return new ForumTopItemAdapter.ForumTopItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ForumTopItemAdapter.ForumTopItemViewHolder holder, int position) {
        holder.button.setText(data.get(position).getName());
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    public class ForumTopItemViewHolder extends RecyclerView.ViewHolder {
        Button button;
        public ForumTopItemViewHolder(@NonNull View itemView) {
            super(itemView);
            button=itemView.findViewById(R.id.forumTopButton);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(onForumTopItemRecyclerItemClickListener!=null){
                        onForumTopItemRecyclerItemClickListener.onItemRecyclerItemClick(getAdapterPosition());
                    }
                }
            });

        }
    }

    public void setOrderItemClickListener(ForumTopItemAdapter.OnForumTopItemRecyclerItemClickListener listener){
        onForumTopItemRecyclerItemClickListener=listener;
    }

    public interface OnForumTopItemRecyclerItemClickListener{
        void onItemRecyclerItemClick(int position);
    }
}
